﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.WorkFlowRegex;
using PickListControl;
namespace AnyOffice.general.system.workflow.flow_type
{   
    public partial class type_set_queryitem : ModulePage
    {
  
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int num = (Request.QueryString["flow_id"] == null) ? 0 : int.Parse(Request.QueryString["flow_id"].ToString());
                this.ViewState["FlowId"] = num;
                FormRegex regex = new FormRegex();
                string str = string.Empty;
                DataTable table = new FlowFormTypeDao().SelectByFlowId(base.Conn, num);
                if ((table.Rows.Count > 0) && (table.Rows[0]["FormModel"] != DBNull.Value))
                {
                    regex.HtmlSource = table.Rows[0]["FormModel"].ToString().ToString();
                }
                ArrayList titleValue = regex.GetTitleValue();
                DataTable table2 = new FlowTypeDao().SelectByFlowId(base.Conn, num);
                if (table2.Rows.Count > 0)
                {
                    this.ViewState["SortId"] = table2.Rows[0]["FlowSort"].ToString();
                    this.litFlowName.Text = table2.Rows[0]["FlowName"].ToString();
                    if (table2.Rows[0]["QueryItem"] != DBNull.Value)
                    {
                        str = "," + table2.Rows[0]["QueryItem"].ToString() + ",";
                    }
                }
                for (int i = 0; i < titleValue.Count; i++)
                {
                    ListItem item = new ListItem(titleValue[i].ToString(), titleValue[i].ToString());
                    if (str.IndexOf("," + titleValue[i].ToString() + ",") >= 0)
                    {
                        this.pklQueryItem.ItemsLeft.Add(item);
                    }
                    else
                    {
                        this.pklQueryItem.ItemsRight.Add(item);
                    }
                }
            }
            if (this.Page.IsPostBack)
            {
                int num3 = Convert.ToInt32(this.ViewState["FlowId"].ToString());
                string str2 = string.Empty;
                foreach (ListItem item2 in this.pklQueryItem.ItemsLeft)
                {
                    str2 = str2 + item2.Value + ",";
                }
                new FlowTypeDao().UpdateQueryItem(base.Conn, num3, str2);
                base.CloseConn();
                Response.Redirect("type_list.aspx?sort_id=" + this.ViewState["SortId"].ToString());
            }
        }

       
    }
}

